<?php
/**
 * 关于发修
 * Author: eecjimmy
 * Date: 2015/6/22
 * Time: 16:02
 */

namespace Wap\Controller;

/**
 * Class AboutController
 * @package Wap\Controller
 */
class KnowController extends WapController
{

    public function index()
    {
        $this->assign('introduce',$this->get_content('introduce')); // 获取介绍
        $this->display();
    }
    
    public function introduce(){
        $this->assign('introduce',$this->get_content('introduce')); // 获取介绍
        $this->display();
    }

    function flash(){
        $where = array();
        if(I('get.video_id')) $where['id'] = intval(I('get.video_id'));
        $video = M('video')->where($where)->order('id desc')->find();
        $video['play_num'] > 10000 && $video['play_num'] = number_format($video['play_num'] / 10000, 1) . '万'; // 如果播放次数大于10000次转换为xxx.x万的格式
        $video_list = M('video')->order('id desc')->field(true)->select();
        $this->assign('video', $video);
        $this->assign('video_list', $video_list);
        $this->display();
    }

    function recruit(){
        $tel = M("config")->where(array("name"=>array("eq","TEL")))->getField("value");
        $this->assign("tel",$tel);
        $job_list = M('job')->order('id desc')->field(true)->select();
        $this->assign('job_list', $job_list);
        $this->display();
    }

    function culture(){
        $this->assign('culture',$this->get_content('culture')); // 获取文化内容
        $this->display();
    }

    function apply()
    {
        if (IS_POST && IS_AJAX) {
            $data['name'] = trim(I('post.name'));
            $data['phone'] = trim(I('post.phone'));
            $data['apply_job'] = trim(I('post.apply_job'));
            $data['sex'] = intval(I('post.sex'));
            if ($data['name'] == '') {
                $this->error('请输入姓名');
            } elseif ($data['phone'] == '') {
                $this->error('请输入电话');
            } elseif (!preg_grep('/^1[3|5|8]\d{9}$/', array($data['phone']))) {
                $this->error('电话号码格式错误');
            } elseif ($data['apply_job'] == '') {
                $this->error('请填写职位');
            } else {
                $data['apply_time'] = date('Y-m-d H:i:s',NOW_TIME);
                if (M('job_apply')->add($data)) {
                    $this->success('申请成功');
                } else {
                    $this->error('申请失败');
                }
            }
        } else {
            E('错误的来路');
        }
    }

    function add_play_num()
    {
        if (IS_AJAX) {
            $where['id'] = intval(I('get.id'));
            M('video')->where($where)->setInc('play_num');
        } else {
            E('错误的来路');
        }
    }

    private function get_content($type){
        $info = M('about')->where(array('type'=>$type))->find();
        $info['pic'] = _parse_pics($info['pic']);
        return $info;
    }
}